home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Mine Sweeper / Source / init.c < prev    next >
Text File  |  1994-04-26  |  2KB  |  99 lines

  1. /*    init.c
  2.  *
  3.  *        How to initialize the basic Macintosh application
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include "event.h"
  8.  
  9. /****************************************************************/
  10. /*                                                                */
  11. /*                        Forward Declarations                    */
  12. /*                                                                */
  13. /****************************************************************/
  14.  
  15. void    InitMacOS(void);                /* Initialize Macintosh */
  16. void    InitMenuBar(void);                /* Init Menu Bar        */
  17.  
  18. /****************************************************************/
  19. /*                                                                */
  20. /*                        Primary Entry Point                        */
  21. /*                                                                */
  22. /****************************************************************/
  23.  
  24. /*    InitApp
  25.  *
  26.  *        The primary entry point for initializing the entire
  27.  *    application program
  28.  */
  29.  
  30. void InitApp()
  31. {
  32.     InitMacOS();                        /* Init Macintosh        */
  33.     InitMenuBar();                        /* Get My Menu Bar        */
  34.     LoadPreferences();                    /* Load prefs file        */
  35. }
  36.  
  37. /*    EndApp
  38.  *
  39.  *        Entry point for saving stuff
  40.  */
  41.  
  42. void EndApp()
  43. {
  44.     SavePreferences();                    /* Save preferences        */
  45. }
  46.  
  47. /****************************************************************/
  48. /*                                                                */
  49. /*                    Local Initialization Code                    */
  50. /*                                                                */
  51. /****************************************************************/
  52.  
  53. /*    InitMacOS
  54.  *
  55.  *        Initialize the various Macintosh Operating System
  56.  *    Managers
  57.  */
  58.  
  59. static void InitMacOS()
  60. {
  61.     int i;
  62.     EventRecord e;
  63.     long l;
  64.     
  65.     InitGraf(&thePort);                    /* Initialize quickdraw    */
  66.     InitCursor();                        /* Initialize my cursor */
  67.     InitFonts();                        /* Initialize fonts        */
  68.     InitWindows();                        /* Initialize windows    */
  69.     InitMenus();                        /* Initialize menu mgr.    */
  70.     TEInit();                            /* Init Text Manager    */
  71.     InitDialogs(NULL);                    /* Init dialogs            */
  72.     FlushEvents(everyEvent,0);            /* Init Event Manager    */
  73.     
  74.     for (i = 0; i < 10; i++)            /* Force me to front    */
  75.         GetNextEvent(everyEvent,&e);    /* in multifinder...    */
  76.     
  77.     GetDateTime((unsigned long *)&l);
  78.     randSeed = l;                        /* Randomize this        */
  79. }
  80.  
  81.  
  82. /*    InitMenuBar
  83.  *
  84.  *        Initialize the menu bar
  85.  */
  86.  
  87. static void InitMenuBar(void)
  88. {
  89.     Handle h;
  90.     MenuHandle mh;
  91.     
  92.     h = GetNewMBar(128);
  93.     SetMenuBar(h);
  94.     mh = GetMHandle(128);
  95.     AddResMenu(mh,'DRVR');
  96.     DrawMenuBar();
  97. }
  98.  
  99.